﻿using System;
using Omabar.BLL;
using Omabar.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Omabar.CMS.CMS
{
    public partial class TripEdit : System.Web.UI.Page
    {
        protected List<PHOTO> photos;
        protected List<FLIGHT> flights;
        protected List<HOTEL> hotels;
        protected List<FOOD> foods;

        protected TRIP trip;

        protected void Page_Load(object sender, EventArgs e)
        {
            Photo_BLL photoBLL = new Photo_BLL();
            Flight_BLL flightBLL = new Flight_BLL();
            Hotel_BLL hotelBLL = new Hotel_BLL();
            Food_BLL foodBLL = new Food_BLL();
            Trip_BLL tripBLL = new Trip_BLL();

            if (!IsPostBack)
            {
                string id = string.IsNullOrEmpty(Request["id"]) ? "0" : Request["id"];
                trip =  tripBLL.GetModel(id);
                if (trip == null) trip = new TRIP();
                //图库
                photos = photoBLL.GetModels(string.Format("SELECT TOP 10 T.PHOTO_ID,PHOTO_NAME,PHOTO_URL,PHOTO_DES,PHOTO_HOT,PHOTO_COVER FROM TRIP_GALLERY T LEFT JOIN PHOTO V ON T.PHOTO_ID=V.PHOTO_ID WHERE T.TRIP_ID='{0}'", id));
                if (photos == null) photos = new List<PHOTO>();
                //航班
                flights = flightBLL.GetModels(string.Format("SELECT TOP 10 T.FLIGHT_ID,FLIGHT_CODE,FLIGHT_CITY_START,FLIGHT_CITY_END,FLIGHT_TIME_START,FLIGHT_TIME_END,FLIGHT_PRICE FROM TRIP_FLIGHT T LEFT JOIN FLIGHT V ON T.FLIGHT_ID=V.FLIGHT_ID WHERE T.TRIP_ID='{0}'", id));
                if (flights == null) flights = new List<FLIGHT>();
                //酒店
                hotels = hotelBLL.GetModels(string.Format("SELECT TOP 10 T.HOTEL_ID,HOTEL_NAME,HOTEL_DES,HOTEL_ADDRESS,HOTEL_WEBSITE,HOTE_DETAIL FROM TRIP_HOTEL T LEFT JOIN HOTEL V ON T.HOTEL_ID=V.HOTEL_ID WHERE T.TRIP_ID='{0}'", id));
                if (hotels == null) hotels = new List<HOTEL>();
                //餐饮
                foods = foodBLL.GetModels(string.Format("SELECT TOP 10 FOOD_ID,BREAKFAST,LUNCH,DINNER FROM FOOD WHERE FOOD_ID='{0}'", trip.TRIP_FOOD));
                if (foods == null) foods = new List<FOOD>();
            }
        }
    }
}